namespace Yyd.Share.Base
{
    public class OperateOutput<T> : OperateOutput, IApiResult<T>
    {
        /// <summary>
        /// 
        /// </summary>
        public T Data { get; set; }

        public OperateOutput<T> SetData(T data)
        {
            Data = data;
            SetOk();
            return this;
        }

        public T GetData()
        {
            return Data;
        }
    }

    public class OperateOutput : BaseResponseDto, IApiResult<string>
    {
        public OperateOutput() : this(false)
        {
        }

        public OperateOutput(bool flag = true, string msg = "操作成功")
        {
            base.OperateFlag = flag;
            base.OperateMsg = msg;
            if (!flag && msg == "操作成功")
            {
                base.OperateMsg = "操作失败";
            }
        }


        public OperateOutput SetError(string msg = "参数错误")
        {
            base.OperateFlag = false;
            base.OperateMsg = msg;
            return this;
        }

        public OperateOutput SetOk(string msg = "操作成功")
        {
            base.OperateFlag = true;
            base.OperateMsg = msg;
            return this;
        }

        public string GetData()
        {
            return string.Empty;
        }
    }

    public class BaseResponseDto
    {
        public bool OperateFlag { get; set; }
        public string OperateMsg { get; set; }
    }

    public interface IApiResult<out T>
    {
        bool OperateFlag { get; set; }

        string OperateMsg { get; set; }
        T GetData();
    }
}